﻿namespace DotRas
{
    using pptpclient.Properties;
    using System;
    using System.Diagnostics;

    [DebuggerDisplay("EntryName = {EntryName}")]
    public sealed class RasConnection : MarshalByRefObject
    {
        private RasDevice _device;
        private Guid _entryId;
        private string _entryName;
        private RasHandle _handle;
        private string _phoneBookPath;
        private int _subEntryId;

        internal RasConnection()
        {
        }

        public bool ClearConnectionStatistics()
        {
            return RasHelper.ClearConnectionStatistics(this.Handle);
        }

        public bool ClearLinkStatistics()
        {
            return RasHelper.ClearLinkStatistics(this.Handle, this.SubEntryId);
        }

        public RasLinkStatistics GetConnectionStatistics()
        {
            return RasHelper.GetConnectionStatistics(this.Handle);
        }

        public RasConnectionStatus GetConnectionStatus()
        {
            return RasHelper.GetConnectionStatus(this.Handle);
        }

        public RasLinkStatistics GetLinkStatistics()
        {
            return RasHelper.GetLinkStatistics(this.Handle, this.SubEntryId);
        }

        public object GetProjectionInfo(RasProjectionType projectionType)
        {
            return RasHelper.GetProjectionInfo(this.Handle, projectionType);
        }

        public RasHandle GetSubEntryHandle(int subEntryId)
        {
            if (subEntryId <= 0)
            {
                DotRas.ThrowHelper.ThrowArgumentException("subEntryId", Resources.Argument_ValueCannotBeLessThanOrEqualToZero);
            }
            return RasHelper.GetSubEntryHandle(this.Handle, subEntryId);
        }

        public bool HangUp()
        {
            return RasHelper.HangUp(this.Handle);
        }

        public RasDevice Device
        {
            get
            {
                return this._device;
            }
            internal set
            {
                this._device = value;
            }
        }

        public Guid EntryId
        {
            get
            {
                return this._entryId;
            }
            internal set
            {
                this._entryId = value;
            }
        }

        public string EntryName
        {
            get
            {
                return this._entryName;
            }
            internal set
            {
                this._entryName = value;
            }
        }

        public RasHandle Handle
        {
            get
            {
                return this._handle;
            }
            internal set
            {
                this._handle = value;
            }
        }

        public string PhoneBookPath
        {
            get
            {
                return this._phoneBookPath;
            }
            internal set
            {
                this._phoneBookPath = value;
            }
        }

        public int SubEntryId
        {
            get
            {
                return this._subEntryId;
            }
            internal set
            {
                this._subEntryId = value;
            }
        }
    }
}

